home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / vol7n2.arc / MODENV.C < prev    next >
Text File  |  1987-12-23  |  1KB  |  39 lines

  1. /*
  2.         MODENV.C    Demonstration of C "putenv" function.
  3.         Copyright (C) 1987 Ziff Communications Co, by Ray Duncan
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <process.h>
  8.  
  9. main(argc,argv,envp)
  10. int argc;
  11. char *argv[];
  12. char *envp[];
  13. {   char comspec[80];           /* COMSPEC= value goes here */
  14.     int status;                 /* scratch storage */
  15.  
  16.                                 /* get location of COMMAND.COM from
  17.                                    environment COMSPEC= variable */
  18.     strcpy( comspec, getenv("COMSPEC") );
  19.     if( comspec[0] == NULL )
  20.         {   puts("\nNo COMSPEC found in environment.");
  21.             exit(1);
  22.         }
  23.                                 /* change PROMPT= environment variable */
  24.     if( putenv("PROMPT=Enter EXIT to Return to MODENV$_$p$g") )
  25.         puts("\nCall to PUTENV failed.");
  26.     
  27.                                 /* announce launch of COMMAND.COM */
  28.     puts("\nNow spawning a new copy of COMMAND.COM.");
  29.  
  30.                                 /* now spawn new command processor */
  31.     if( spawnle(P_WAIT,comspec,comspec,NULL,envp) == -1 )
  32.         puts("\nEXEC of COMMAND.COM failed");
  33.  
  34.                                 /* announce return from COMMAND.COM */
  35.     puts("\nBack from new COMMAND.COM, MODENV is exiting.");
  36.  
  37.     exit(0);                    /* now terminate */
  38. }
  39.